home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’87 / Source ƒ.sit / Source ƒ / C ƒ / TRANS-LSC / Skel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-06-30  |  4.4 KB  |  217 lines  |  [TEXT/KAHL]

  1. /*
  2.     TransSkel demonstration:  Traditional Skel
  3.  
  4.     This program mimics the original Skel application:  one sizable,
  5.     dragable, non-closable dark gray window, an "About" alert and two
  6.     dialogs.  Desk accessories supported.
  7.  
  8.     The project should include this file, TransSkel.c (or a project
  9.     built from TransSkel.c), and MacTraps.
  10.  
  11.     27 June 1986        Paul DuBois
  12. */
  13.  
  14. # include    <DialogMgr.h>    /* includes WindowMgr, QuickDraw, etc. */
  15. # include    <MenuMgr.h>
  16. # include    <ToolboxUtil.h>
  17.  
  18. # define    nil    0L
  19.  
  20. /*
  21.     Resource numbers
  22. */
  23.  
  24. # define    fileMenuRes    2        /* File menu */
  25. # define    aboutAlrt    1000    /* About box */
  26. # define    theWindRes    260        /* window */
  27. # define    reportDlog    257        /* message dialog box */
  28. # define    aboutStr    1        /* message strings */
  29. # define    rattleStr    2
  30. # define    frightStr    3
  31.  
  32.  
  33.  
  34. /* file menu item numbers */
  35.  
  36. typedef enum {
  37.     rattle = 1,
  38.     frighten,
  39.     /* --- */
  40.     quit = 4
  41. } fileItems;
  42.  
  43.  
  44. WindowPtr    theWind;
  45.  
  46. /*
  47.     Menu handles.  There isn't any apple menu here, since TransSkel will
  48.     be told to handle it itself.
  49. */
  50.  
  51. MenuHandle    fileMenu;
  52.  
  53.  
  54. /* -------------------------------------------------------------------- */
  55. /*                        Menu handling procedures                        */
  56. /* -------------------------------------------------------------------- */
  57.  
  58.  
  59. /*
  60.     Read a string resource and put into the Alert/Dialog paramtext
  61.     values
  62. */
  63.  
  64. SetParamText (strNum)
  65. int        strNum;
  66. {
  67. StringHandle    h;
  68.  
  69.     h = GetString (strNum);
  70.     HLock (h);
  71.     ParamText (*h, "\p", "\p", "\p");
  72.     HUnlock (h);
  73. }
  74.  
  75.  
  76. /*
  77.     Handle selection of "About Skel…" item from Apple menu
  78. */
  79.  
  80. DoAbout ()
  81. {
  82. StringHandle    h;
  83.  
  84.     SetParamText (aboutStr);
  85.     (void) Alert (aboutAlrt, nil);
  86. }
  87.  
  88.  
  89. /*
  90.     Put up a dialog box with a message and an OK button.  The message
  91.     is stored in the 'STR ' resource whose number is passed as strNum.
  92. */
  93.  
  94. Report (strNum)
  95. int        strNum;
  96. {
  97. DialogPtr        theDialog;
  98. int                itemHit;
  99.  
  100.     SetParamText (strNum);
  101.     theDialog = GetNewDialog (reportDlog, nil, -1L);
  102.     ModalDialog (nil, &itemHit);
  103.     DisposDialog (theDialog);
  104. }
  105.  
  106.  
  107. /*
  108.     Process selection from File menu.
  109.     
  110.     Rattle, Frighten    A dialog box with message
  111.     Quit    Request a halt by calling SkelHalt().  This makes SkelMain
  112.             return.
  113. */
  114.  
  115. DoFileMenu (item)
  116. int        item;
  117. {
  118.  
  119.     switch (item)
  120.     {
  121.         case rattle:    Report (rattleStr); break;
  122.         case frighten:    Report (frightStr); break;
  123.         case quit:        SkelWhoa (); break;    /* request halt */
  124.     }
  125. }
  126.  
  127.  
  128. /*
  129.     Initialize menus.  Tell TransSkel to process the Apple menu
  130.     automatically, and associate the proper procedures with the
  131.     File and Edit menus.
  132. */
  133.  
  134. SetUpMenus ()
  135. {
  136.  
  137.     SkelApple ("\pAbout Skel…", DoAbout);
  138.     fileMenu = GetMenu (fileMenuRes);
  139.     SkelMenu (fileMenu, DoFileMenu, nil);
  140. }
  141.  
  142.  
  143. /* -------------------------------------------------------------------- */
  144. /*                    Window handling procedures                            */
  145. /* -------------------------------------------------------------------- */
  146.  
  147.  
  148. WindActivate (active)
  149. Boolean    active;
  150. {
  151.  
  152.     DrawGrowIcon (theWind);    /* make grow box reflect new window state */
  153. }
  154.  
  155.  
  156. /*
  157.     On update event, can ignore the resizing information, since the whole
  158.     window is always redrawn in terms of the current size, anyway.
  159.     Content area is dark gray except scroll bar areas, which are white.
  160.     Draw grow box as well.
  161. */
  162.  
  163. WindUpdate (resized)
  164. Boolean    resized;
  165. {
  166. Rect    r;
  167.  
  168.     r = theWind->portRect;        /* paint window dark gray */
  169.     r.bottom -= 15;                /* don't bother painting the */
  170.     r.right -= 15;                /* scroll bar areas */
  171.     FillRect (&r, dkGray);
  172.     r = theWind->portRect;        /* paint scroll bar areas white */
  173.     r.left = r.right - 15;
  174.     FillRect (&r, white);
  175.     r = theWind->portRect;
  176.     r.top = r.bottom - 15;
  177.     FillRect (&r, white);
  178.     DrawGrowIcon (theWind);
  179. }
  180.  
  181.  
  182. WindHalt () { CloseWindow (theWind); }
  183.  
  184.  
  185. /*
  186.     Read window from resource file and install handler for it.  Mouse
  187.     and key clicks are ignored.  There is no close proc since the window
  188.     doesn't have a close box.  There is no idle proc since nothing is
  189.     done while the window is in front (all the things that are done are
  190.     handled by TransSkel).
  191. */
  192.  
  193. WindInit ()
  194. {
  195.  
  196.     theWind = GetNewWindow (theWindRes, nil, -1L);
  197.     SetPort (theWind);
  198.     SkelWindow (theWind, nil, nil, WindUpdate, WindActivate, nil,
  199.                     WindHalt, nil, false);
  200. }
  201.  
  202.  
  203. /* -------------------------------------------------------------------- */
  204. /*                                    Main                                */
  205. /* -------------------------------------------------------------------- */
  206.  
  207.  
  208. main ()
  209. {
  210.  
  211.     SkelInit ();                /* initialize */
  212.     SetUpMenus ();                /* install menu handlers */
  213.     WindInit();                    /* install window handler */
  214.     SkelMain ();                /* loop 'til Quit selected */
  215.     SkelClobber ();                /* clean up */
  216. }
  217.